package com.reservation.controller.user.home;

import com.reservation.dto.user.home.UpdateInfoDTO;
import com.reservation.result.Result;
import com.reservation.service.HomeService;
import com.reservation.vo.user.home.GetSystemInfoVO;
import com.reservation.vo.user.home.GetTypeCountVO;
import com.reservation.vo.user.home.GetWeekCountArrVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "首页相关接口")
@RestController
@RequestMapping("/api/user")
@Slf4j

public class HomeController {

    @Autowired
    private HomeService homeService;

    @PostMapping("/updateInfo")
    public Result updateInfo(@RequestBody UpdateInfoDTO updateInfoDTO) {

        return homeService.updateInfo(updateInfoDTO) ? Result.success() : Result.error("更新失败");
    }

    @PostMapping("/getSystemInfo")
    public Result getSystemInfo() {

        GetSystemInfoVO getSystemInfoVO = homeService.getSystemInfo();
        return getSystemInfoVO == null ? Result.error("查询失败") : Result.success(getSystemInfoVO) ;
    }

    @PostMapping("/getTypeCount")
    public Result getTypeCount() {

        List<GetTypeCountVO> getTypeCountVO = homeService.getTypeCount();
        return Result.success(getTypeCountVO) ;
    }

    @PostMapping("/getWeekCount")
    public Result getWeekCount() {

        GetWeekCountArrVO arr = homeService.getWeekCountArr();
        return Result.success(arr) ;
    }


}
